package com.shujia.core

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object Demo10Union {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf()
    conf.setMaster("local")
    conf.setAppName("Union算子演示")
    val context = new SparkContext(conf)
    //====================================================
    val w1RDD: RDD[String] = context.textFile("spark/data/ws/w1.txt") // 1
    val w2RDD: RDD[String] = context.textFile("spark/data/ws/w2.txt") // 1

    /**
     *  union:上下合并两个RDD,前提是两个RDD中的数据类型要一致，合并后不会对结果进行去重
     *
     *  注：这里的合并只是逻辑层面上的合并，物理层面其实是没有合并
     */

    val unionRDD: RDD[String] = w1RDD.union(w2RDD)
    println(unionRDD.getNumPartitions) // 2


    unionRDD.foreach(println)
    while (true){

    }


  }
}
